package com.api.gbhg.lbj.action;


import com.api.gbhg.liwenjun.GBHGConstant;
import com.api.gbhg.liwenjun.VersionFlowUtil;
import com.api.gbhg.luoao.tool.ToolCURD;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import weaver.conn.RecordSet;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;

/**
 * @author lbj
 * @version 1.0
 * @description: TODO 通用项目新增表 同步表单数据
 * @date 2020/12/23 17:19
 */
public class GeneralProjectAction implements Action {
    private static final Logger logger = LoggerFactory.getLogger("gbhg");
    @Override
    public String execute(RequestInfo requestInfo) {
        logger.info("-----------------通用项目新增表------------------------");
        Map<String,String> map = new HashMap<>();
        map.put("xmmin", "xmmc");
        map.put("sbks","sbks");
        map.put("sydw","sydw");
        RecordSet rs = ToolCURD.selectDetailnanlist(requestInfo, 3);
        double yszje = 0;
        while (rs.next()){
            String hjwy =  rs.getString("hjwy");
            if(!hjwy.isEmpty()){
                yszje = Double.parseDouble(hjwy)+yszje;
                if (yszje<0){
                    yszje=0;
                }
            }
        }
        //同步流程数据到版本表、主表
        boolean isSuccess = VersionFlowUtil.sysDataToVersion(requestInfo.getRequestid(), requestInfo.getWorkflowid(), GBHGConstant.FlowVersionTableEnum.uf_tyxmxzbbb, map);
        //把预算总金额插入到主表中
        boolean up = ToolCURD.updateVersionQuery(yszje, requestInfo.getRequestid());
        if(!isSuccess||!up){
            logger.info("同步流程数据到版本表失败！");
            requestInfo.getRequestManager().setMessagecontent("同步建模表数据异常");
            requestInfo.getRequestManager().setMessageid("1000");
            return FAILURE_AND_CONTINUE;
        }
            return SUCCESS;
        }
    }

